import json
from flask import Flask
from wsgiref.simple_server import make_server

app = Flask(__name__)

@app.route('/user/<username>')
def root_func(username):
    users = [
        {"name": "Tom", "age": "18", "sex": 1},
        {"name": "Coral", "age": "17", "sex": 0},
        {"name": "Kate", "age": "18", "sex": 0}
    ]

    for user in users:
        if user["name"].lower() == username.lower():
            return json.dumps(user)

    return json.dumps({"errMsg": "can not find the user!"})

if  __name__ == '__main__':
    server = make_server('127.0.0.1',5000,app) #外部访问的url,端口
    server.serve_forever()
    app.run()

